/*
 * Copyright 2009 Michal Trzcinka
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed
 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
 * CONDITIONS OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 */
( function() {

  YAHOO.namespace('TRZCINKA.VCARD');

  YAHOO.TRZCINKA.VCARD.Map = function(obj) {
    this._hash = obj || {};
  };

  YAHOO.TRZCINKA.VCARD.Map.prototype.add = function (key, val) {
    this._hash[key] = val;
  };

  YAHOO.TRZCINKA.VCARD.Map.prototype.remove = function (key) {
    delete this._hash[key];
  };

  YAHOO.TRZCINKA.VCARD.Map.prototype.get = function (key) {
    if (this._hash.hasOwnProperty(key)) {
      return this._hash[key];
    }
    return undefined;
  };

  YAHOO.TRZCINKA.VCARD.Map.prototype.each = function(f) {
    for (var k in this._hash) {
      if (this._hash.hasOwnProperty(k)) {
        f({key: k, value: this._hash[k]});
      }
    }
  };

  YAHOO.TRZCINKA.VCARD.Map.prototype.containsKey = function (key) {
    return this._hash.hasOwnProperty(key);
  };

  YAHOO.TRZCINKA.VCARD.Map.prototype.getKeys = function () {
    var res = [];
    for (var k in this._hash) {
      if (this._hash.hasOwnProperty(k)) {
        res.push(k);
      }
    }
    return res;
  };

  YAHOO.TRZCINKA.VCARD.Map.prototype.getValues = function () {
    var res = [];
    for (var k in this._hash) {
      if (this._hash.hasOwnProperty(k)) {
        res.push(this._hash[k]);
      }
    }
    return res;
  };

})();